// 所有菜单切换时加背景色
qsAll('.nav li a').forEach((item, index) => {
  item.onclick = function () {
    qsAll('.nav li a').forEach(item => item.classList.remove('active'))
    this.classList.add('active')
  }
  // 默认首个a标签高亮
  if (index === 0) item.onclick()
})


// 退出登录
if (localStorage.getItem('token') === null) location.href = './login.html'
qs('.right .logout').onclick = function () {
  if (!confirm('你确定要退出登录吗？')) return
  localStorage.removeItem('token')
  location.href = './login.html'
}

// 初始化数据
qs('.right .init').onclick = function () {
  axios.get('/init/data').then(({data: {code, message}}) => {
    // console.log(data)
    if (code === 0) {
      alert(message)
    }
  })
}